﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;

public class ArtillaryParameter : FlyItemParameter
{
    public Dropdown m_HeadType;
    public Slider m_JetChargeSlider;
    public Text m_JetChargeL;
    public Slider m_ExplotionChargeSlider;
    public Text m_ExplotionChargeL;

    public GameObject m_ExplotionChargePanel;
    void Start()
    {
    }
    void Update()
    {
    }
    public override void Init(FlyItem flyItem)
    {
        base.Init(flyItem);
        var artillery = m_FlyItem as FlyItemArtillery;

        m_JetChargeSlider.minValue = 0;
        m_JetChargeSlider.maxValue = artillery.maxCharge;
        m_JetChargeSlider.value = artillery.jetCharge;

        m_ExplotionChargeSlider.minValue = 0;
        m_ExplotionChargeSlider.maxValue = artillery.maxCharge;
        m_ExplotionChargeSlider.value = artillery.explotionCharge;
        m_HeadType.value = (int)artillery.headType;
        UpdateInformation(artillery);
    }
    public void OnJetChargeSliderChanged(Single value)
    {
        var artillery = m_FlyItem as FlyItemArtillery;
        artillery.jetCharge = (float)value;
        m_JetChargeL.text = value.ToString("0.0") + "kg";
        UpdateInformation(artillery);
    }
    public void OnExplotionChargeSliderChanged(Single value)
    {
        var artillery = m_FlyItem as FlyItemArtillery;
        artillery.explotionCharge = (float)value;
        m_ExplotionChargeL.text = value.ToString("0.0") + "kg";
        UpdateInformation(artillery);
    }
    public void OnHeadTypeChanged(int value)
    {
        var artillery = m_FlyItem as FlyItemArtillery;
        artillery.headType = (FlyItemArtillery.HeadType)m_HeadType.value;
        UpdateInformation(artillery);
    }
    private void UpdateInformation(FlyItemArtillery artillery)
    {
        m_WeightL.text = (artillery.CalcMass() * 1000f).ToString("0.0") + "kg";
        m_ShotFrequencyL.text = artillery.CalcShotFrequency().ToString("0.0") +  "s";
        m_ReloadFrequencyL.text = artillery.CalcReloadFrequency().ToString("0.0") + "s";
        switch(artillery.headType)
        {
            case FlyItemArtillery.HeadType.Collision:
                m_ExplotionChargePanel.SetActive(false);
                break;
            case FlyItemArtillery.HeadType.Explotion:
                m_ExplotionChargePanel.SetActive(true);
                break;
        }
    }
}